# @Author：silence
# @Email：792245022@qq.com
# @Date：2025/3/2 19:57

import urllib.request
import urllib.parse
import json

"""
post 请求方式的参数，必须编码
编码之后，必须调用 encode 方法
参数是放在请求对象定制的方法中
"""

# post 请求
url = "https://fanyi.baidu.com/v2transpai?form=en&to=zh"

headers = {
    "accept": "*/*",
    # "accept-encoding": "gzip, deflate, br, zstd",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
    "connection": "keep-alive",
    "content-length": "7",
    "content-type": "application/x-www-form-urlencoded",
    "cookie": "Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1711453569; H_WISE_SIDS_BFESS=60277_60599_60360_60824; BAIDUID_BFESS=DF507A21E00C2BE480CC75B9A320DF65:SL=0:NR=10:FG=1; ZFY=GwYi44nyxRzFjIpZshGXU3y3fPCL0B5x:BMt7zTBAQsI:C; BDUSS=jlEZXJKejhWbkk0R1lRZ1NRWnJGcVhPbGFLT3FjaTJ1eHBYQkZjNkd6TE91R1ZuSVFBQUFBJCQAAAAAAAAAAAEAAADh8iCcc2t5x7PQpnBwcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM4rPmfOKz5nM; BDUSS_BFESS=jlEZXJKejhWbkk0R1lRZ1NRWnJGcVhPbGFLT3FjaTJ1eHBYQkZjNkd6TE91R1ZuSVFBQUFBJCQAAAAAAAAAAAEAAADh8iCcc2t5x7PQpnBwcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM4rPmfOKz5nM; BIDUPSID=DF507A21E00C2BE480CC75B9A320DF65; PSTM=1734185706; __bid_n=194fb66ffd301443109bb4; H_WISE_SIDS=62257_62325_62346_62328; arialoadData=false; H_PS_PSSID=60277_61027_61671_62127_62167_62234_62257_62325_62338_62346_62328_62373_62387; BA_HECTOR=05800h2k0h058gakak25agal3btjon1js8fld1u; delPer=0; PSINO=1; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; ab_sr=1.0.1_OWU5OGFkMTY2NGVmOGI5YmMzZmI3YTViZGM2NjNmOTYyNDk0ZmY2MjBlNTRhOGI4M2Y2MDcyOGNlNGYxMmFjNjVjYTE3YjdjMGE4YzllZjI2NjAyNzRiNzQyY2U1NDllOWU5ZTM1ZDM0ZjlmNmZiM2Q0ZTMyMzEzMjQ2NDBlOGIzMWIxYjBlNjdkNTdkZWUwNjY3Mzg5N2UyZWE2MGQ3OQ==; RT=\"z=1&dm=baidu.com&si=ddbb5fde-35c8-45ea-8471-e5eeed81e9fe&ss=m7rqeh5y&sl=1&tt=of&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=1gf\"",
    "host": "fanyi.baidu.com",
    "origin": "https://fanyi.baidu.com",
    "referer": "https://fanyi.baidu.com/mtpe-individual/multimodal?query=lov&lang=en2zh",
    "sec-ch-ua": "\"Not(A:Brand\";v=\"99\", \"Google Chrome\";v=\"133\", \"Chromium\";v=\"133\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
}

data = {
    "from": "en",
    "to": "zn",
    "query": "love",
    "transtype": "realtime",
    "simple_means_flag": "3",
    "sign": "198772.518981",
    "token": "5483bfa652979b41f9c90d91f3de875d",
    "domain": "common"
}

# post 请求的参数，必须要进行编码
data = urllib.parse.urlencode(data).encode("utf-8")

request = urllib.request.Request(url, data, headers, method="POST")

response = urllib.request.urlopen(request)
content = response.read().decode("utf-8")

# obj = json.loads(content)
# obj = json.dumps(obj)

print(content)